package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.mapper.ShoppingCartMapper;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: ShoppingCartController
 * Package: com.sky.controller.user
 * Description:
 *
 * @Author Dylan_Jun
 * @Create 2024/2/19 10:05
 * @Version 1.0
 */
@Slf4j
@RestController
@Api(tags = "购物车相关接口")
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO dto){
        log.info("添加购物车，{}", dto);
        shoppingCartService.insert(dto);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> listAll(){
        log.info("查看购物车");
        List<ShoppingCart> list = shoppingCartService.listAll();
        return Result.success(list);
    }

    @DeleteMapping("clean")
    @ApiOperation("清空购物车")
    public Result cleanAll(){
        log.info("清空购物车");
        shoppingCartService.cleanAll();
        return Result.success();
    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车指定商品")
    public Result sub(@RequestBody ShoppingCartDTO dto){
        log.info("删除指定商品");
        shoppingCartService.sub(dto);
        return Result.success();
    }
}
